/****************************************************************************
**
** Copyright (C) 2009-2010 Mist Poryvaev.
** All rights reserved.
** Contact: Mist Poryvaev (mist.poryvaev@gmail.com)
**
** This file is part of the RailWorm project.
**
****************************************************************************/

#ifndef ORDERTICKETS_H
#define ORDERTICKETS_H

#include <QtGui>
#include "parsetraindata.h"
#include "setuplogon.h"
#include "htmlgenie.h"

namespace Ui {
    class OrderTickets;
}

class OrderTickets : public QDialog {
    Q_OBJECT
public:	
    ~OrderTickets();
	static OrderTickets * i();

protected:

private:
    OrderTickets(QWidget *parent = 0);
    static OrderTickets * g_Instance;
    Ui::OrderTickets *ui;
    SetupLogon * m_SetupLogon;
	TrainDataStruct m_tds;
	QComboBox * m_DocType;

	QWebView * bank, * login;

	QDateTime m_LastAccessTime;
	QString m_LoggedInResponse;
	QString m_Login, m_Password, m_BankUrl, m_LoginUrl, m_BuyUrl;
	QString m_VehicleCode;

	HtmlGenie jinn;

	void QuitAccount(HtmlResponse * _response = 0, bool _error = false);
	bool CheckLoggedIn(const QString & _data);

	enum {PD_SURNAME = 0, PD_NAME, PD_MIDNAME, PD_TYPE, PD_SERIAL};
public slots:
    void Execute(TrainDataStruct tds);

private slots:
	void on_tabWidget_currentChanged(int index);
	void on_NextPage_clicked();
    void on_PrevPage_clicked();

	void OnStartPageFinished(HtmlResponse * Response, int Id, bool _Error);
	void OnLoginPageFinished(HtmlResponse *  Response, int Id, bool _Error);
	void OnLoggedPageFinished(HtmlResponse *  Response, int Id, bool _Error);
	void OnBuyPageFinished(HtmlResponse *  Response, int Id, bool _Error);
	void OnFromToPageFinished(HtmlResponse *  Response, int Id, bool _Error);
	void OnSelectTrainPageFinished(HtmlResponse *  Response, int Id, bool _Error);
	void OnSelectVehiclePageFinished(HtmlResponse *  Response, int Id, bool _Error);
	void OnPersonalDataPageFinished(HtmlResponse *  Response, int Id, bool _Error);
	void OnCheckParamsPageFinished(HtmlResponse *  Response, int Id, bool _Error);
	void OnCheckOrderPageFinished(HtmlResponse *  Response, int Id, bool _Error);
	void OnPayPageFinished(HtmlResponse *  Response, int Id, bool _Error);

	void OnGateFinished(bool _ok);
	void OnAccountFinished(bool _ok);
};

#endif // ORDERTICKETS_H
